﻿using System;
using System.Data;

namespace Flagwind.Data
{
	/// <summary>
	/// 连接会话对象类。
	/// </summary>
	public class ConnectionSession : IDisposable
	{
		#region 公共属性

		public IDbConnection Connection
		{
			get;
			private set;
		}

		#endregion

		#region 构造方法

		/// <summary>
		/// 以一个使用的连接初始化本类
		/// </summary>
		/// <param name="connection"></param>
		public ConnectionSession(IDbConnection connection)
		{
			this.Connection = connection;
		}

		#endregion

		#region IDisposable 实现

		/// <summary>
		/// 释放连接
		/// </summary>
		public void Dispose()
		{
			if(this.Connection != null && this.Connection.State == ConnectionState.Open)
			{
				this.Connection.Close();
				this.Connection.Dispose();
				this.Connection = null;
			}
		}

		#endregion
	}
}